//
//  YQDetailUserInfoViewController.swift
//  yq微信
//
//  Created by Me yq on 2017/9/26.
//  Copyright © 2017年 yq. All rights reserved.
//

import UIKit

class YQDetailUserInfoViewController: UITableViewController {
    @IBOutlet weak var userName: UILabel!

    // 设置用户名
    var buddy2:String?
   
    // 系统回调函数
    override func viewDidLoad() {
        super.viewDidLoad()
        self.yq_addFootViewBtn()
        self.title = "消息资料"
    }

    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.tabBarController?.tabBar.isHidden = true
    
    }
    
    
    override func viewWillLayoutSubviews() {
        self.userName.text = buddy2
    }
    
    // 快速创建detailUserInfoVc
    class func yq_detailUserInfoVc() -> AnyObject?{
        return UIStoryboard(name: String(describing: self), bundle: nil).instantiateViewController(withIdentifier: String(describing: self)) 
    }
    
    //MARK: 添加(好友详情 发消息) 按钮
    func yq_addFootViewBtn(){
        
        let footerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        // 测试
//        footerView.backgroundColor = UIColor.red
        let btn : UIButton = UIButton(frame: CGRect(x: 30, y: 0, width: self.tableView.bounds.width - 60, height: 40))
        btn.addTarget(self, action: #selector(btnCLick), for: .touchUpInside)

        btn.setTitle("发消息", for: .normal)
        btn.setTitleColor(UIColor.white, for: .normal)
       
        // 设置圆角
        btn.layer.cornerRadius = 5
        // 裁剪
        btn.layer.masksToBounds = true
        
        if #available(iOS 10.0, *) {
            btn.backgroundColor = UIColor(displayP3Red: 51.0/255.0, green: 180.0/255.0, blue: 23.0/255.0, alpha: 1)
       } else {
            // Fallback on earlier versions
        }
        
        footerView.addSubview(btn)
        self.tableView.tableFooterView = footerView
    }
    
    func btnCLick(){
        print("跳转聊天窗口")
        // 拿到tabbarController
        let tabbarVC = UIApplication.shared.keyWindow?.rootViewController as! YQTabBarController
        
        // 拿到微信控制器
        let weixinVC = tabbarVC.viewControllers?[0] as! UINavigationController
        tabbarVC.selectedViewController = weixinVC
        
        let chatVC = YQChatViewController()
        chatVC.buddy = buddy2
        chatVC.view.frame = UIScreen.main.bounds
        weixinVC.pushViewController(chatVC, animated: true)
    }

    
}
